package com.ericsson.enap.modules.procLog.task;

import com.ericsson.common.quartz.task.ManualTask;
import com.ericsson.common.util.LogFileName;
import com.ericsson.common.util.LoggerUtils;
import com.ericsson.enap.modules.procLog.constant.ProcConstant;
import com.ericsson.enap.modules.procLog.service.ImsBossKpiService;
import com.ericsson.enap.modules.sys.entity.EpcDict;
import com.ericsson.enap.modules.sys.service.EpcDictService;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.Date;

/**
 * @description: ImsBossKpi任务
 * @author: yanghai
 * @create: 2021-05-25
 */
@Lazy(true)
@Component
public class ImsBossKpiTask implements ManualTask  {

    private Logger log = LoggerUtils.Logger(LogFileName.ImsBossKpiJob);

    @Autowired
    private ImsBossKpiService imsBossKpiService;
    @Autowired
    private EpcDictService epcDictService;
    @Value("${collectorIp}")
    private String collectorIp;

    @Override
    public void execute() {
        Date now = new Date();
        log.info("===== do imsBossKpiTask start =====: "+now);
        //删除过期数据
        imsBossKpiService.deleteMongodbData(now);
        //读取文件存储路径
        String bossKpiPath = epcDictService.selectEpcDict(new EpcDict(ProcConstant.ProcLogPath)).getKeyValue()+ File.separator+"BOSSKPI";
        String delay=epcDictService.selectEpcDict(new EpcDict(ProcConstant.ProcDelay)).getKeyValue();
        //EDA网元下载BOSS_KPI文件，并解析文件及入库
        imsBossKpiService.dealBossKpiFile(collectorIp,bossKpiPath,now,delay);
    }
}
